<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('客户订单跟踪批次信息')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse" style="display: none;">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>生产工单号：</label>
                                <input type="text" name="moId" id="moId"/>
                            </li>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="customerOrder" id="customerOrder"/>
                            </li>
                            <li>
                                <label>状态大类：</label>
                                <input type="text" name="comClass" id="comClass"/>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('promanage:cusordertrailot:edit')}]];
        var removeFlag = [[${@permission.hasPermi('promanage:cusordertrailot:remove')}]];
        var prefix = ctx + "promanage/cusordertrailot";
        var moId = [[${moId}]];
        var customerOrder = [[${customerOrder}]];
        var comClass = [[${comClass}]];
        var columns = [
            {
                field: 'NO',
                title: "序号",
                formatter: function (value, row, index) {
                    return $.table.serialNumber(index);
                }
            },
            {
                field: 'id',
                title: '编号',
                visible: false
            },
            {
                field: 'timeFlag',
                align: 'center',
                title: '日期时间标识',
                visible: false
            },
            {
                field: 'orderTime',
                align: 'center',
                title: '订单日期'
            },
            {
                field: 'customerOrder',
                align: 'center',
                title: '订单号',
                formatter: function(value, row, index) {
                    return '<a class="" onclick="cusOrderClick(\'' + row.customerOrder + '\')">' + row.customerOrder + '</a>';
                }
            },
            {
                field: 'customerName',
                align: 'center',
                title: '客户名称'
            },
            {
                field: 'orderQty',
                align: 'center',
                title: '订单产品片数'
            },
            {
                field: 'moId',
                align: 'center',
                title: '生产工单号'
            },
            {
                field: 'lotId',
                align: 'center',
                title: '批次号',
                formatter: function(value, row, index) {
                    return '<a class="" onclick="lotIdClick(\'' + row.lotId + '\')">' + row.lotId + '</a>';
                },
                sortable: true
            },
            {
                field: 'partType',
                align: 'center',
                title: '产品类型'
            },
            {
                field: 'partName',
                align: 'center',
                title: '产品名称'
            },
            {
                field: 'lotType',
                align: 'center',
                title: '批次类型'
            },
            {
                field: 'priority',
                align: 'center',
                title: '等级'
            },
            {
                field: 'mainQty',
                align: 'center',
                title: '片数',
                sortable: true,
                footerFormatter:function (value) {
                    // 统计报废总片数
                    var sumQty = 0;
                    for (var i in value) {
                        sumQty += parseFloat(value[i].mainQty);
                    }
                    return "总片数：" + sumQty;
                }
            },
            {
                field: 'lotStartTime',
                align: 'center',
                title: '投片时间',
                sortable: true
            },
            {
                field: 'planEndDate',
                align: 'center',
                title: '计划完工日期',
                sortable: true
            },
            {
                field: 'comClass',
                align: 'center',
                title: '当前状态大类',
                sortable: true
            },
            {
                field: 'state',
                align: 'center',
                title: '状态小类',
                sortable: true
            },
            {
                field: 'countGkb',
                align: 'center',
                title: '总光刻数',
                sortable: true
            },
            {
                field: 'leftGkb',
                align: 'center',
                title: '剩余光刻数',
                sortable: true
            },
            {
                field: 'normTimeDiff',
                align: 'center',
                title: '标准时间差(天)',
                sortable: true,
                formatter: function(value, row, index) {
                    if (null == value) {
                        return;
                    }
                    if (value < 0) {
                        return '<div class="font-bold text-navy">' + value + '</div>';
                    } else {
                        return '<div class="font-bold text-danger">' + value + '</div>';
                    }
                    // return '<a class="" onclick="sumNumClick(\'' + row.partId + '\')">' + row.partId + '</a>';
                }
            },
            {
                field: 'lotShipTime',
                align: 'center',
                title: '入库时间',
                sortable: true
            },
            {
                field: 'lotCycleTime',
                align: 'center',
                title: '生产周期(天)',
                sortable: true
            },
            {
                field: 'scrapQty',
                align: 'center',
                title: '报废数量',
                footerFormatter:function (value) {
                    // 统计报废总片数
                    var sumQty = 0;
                    for (var i in value) {
                        sumQty += parseFloat(value[i].scrapQty);
                    }
                    return "报废总片数：" + sumQty;
                },
                formatter: function(value, row, index) {
                    return '<a class="" onclick="scrapQtyClick(\'' + row.lotId + '\')">' + row.scrapQty + '</a>';
                }
            }
        ];
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "客户订单跟踪批次信息",
            columns: columns,
            striped: true,
            showFooter: true,
            pagination: false,
            sidePagination: "client",
            footerStyle: footerStyle
        };

        $(function() {
            $("#moId").attr("value", moId);
            $("#customerOrder").attr("value", customerOrder);
            $("#comClass").attr("value", comClass);
            $.table.init(options);
        });

        function footerStyle(column) {
            return {
//         	    userBalance: {
//         	        classes: 'class'
//         	    },
                mainQty: {
                    css: { color: 'red', 'font-weight': 'normal' }
                },
                scrapQty: {
                    css: { color: 'red', 'font-weight': 'normal' }
                }
            }[column.field]
        }

        // 客户订单超链接
        function cusOrderClick(customerOrder) {
            var url = "promanage/cusorderdetail" + "/orderdetail?customerOrder=" + customerOrder;
            var options = {
                title: '订单详情',
                btn: 0,
                url: url,
                full: true,
                width: 800,
                height: $(window).height() - 50
            };
            $.modal.openOptions(options);
        }

        // 报废片数超链接
        function scrapQtyClick(lotId) {
            var url = "promanage/scrapinfo" + "/link?lotId=" + lotId;
            var options = {
                title: '报废详情',
                btn: 0,
                url: url,
                full: true,
                width: 800,
                height: $(window).height() - 50
            };
            $.modal.openOptions(options);
        }
        
        // 批次号超链接
        function lotIdClick(lotId) {
            var url = "promanage/cusorderlotwip" + "/wipdetail?lotId=" + lotId;
            var options = {
                title: '批次详情',
                btn: 0,
                url: url,
                full: true,
                width: 800,
                height: $(window).height() - 50
            };
            $.modal.openOptions(options);
        }
    </script>
</body>
</html>